﻿using System;
using System.ComponentModel;

namespace XchangeStreamer.OutputSdk.ViewModel
{
    [Serializable]
    public sealed class OrderBookRecord : INotifyPropertyChanged
    {
        #region Private Fields

        private decimal price;
        private double quantity;
        private decimal splits;
        private decimal turnOver;

        #endregion

        #region Constructors

        private OrderBookRecord()
        { }

        public OrderBookRecord(decimal price, double quantity, decimal splits, decimal turnOver)
        {
            this.price = price;
            this.quantity = quantity;
            this.splits = splits;
            this.turnOver = turnOver;
        }

        #endregion

        #region Public Properties

        public decimal Price
        {
            get
            {
                return this.price;
            }
            set
            {
                if (this.price != value)
                {
                    this.price = value;
                    this.InvokePropertyChanged("Price");
                }
            }
        }

        public double Quantity
        {
            get
            {
                return this.quantity;
            }
            set
            {
                if (this.quantity != value)
                {
                    this.quantity = value;
                    this.InvokePropertyChanged("Quantity");
                }
            }
        }

        public decimal Splits
        {
            get
            {
                return this.splits;
            }
            set
            {
                if (this.splits != value)
                {
                    this.splits = value;
                    this.InvokePropertyChanged("Splits");
                }
            }
        }

        public decimal TurnOver
        {
            get
            {
                return this.turnOver;
            }
            set
            {
                if (this.turnOver != value)
                {
                    this.turnOver = value;
                    this.InvokePropertyChanged("TurnOver");
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void InvokePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                try
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
                }
                catch { }
            }
        }

        #endregion

        public string GetValue(string propName)
        {
            switch (propName)
            {
                case "Price":
                    return this.price.ToString();
                case "Quantity":
                    return this.quantity.ToString();
                case "Splits":
                    return this.splits.ToString();
                case "TurnOver":
                    return this.turnOver.ToString();
                default:
                    return null;
            }
        }
    }
}
